import GoodsClassifyiComp from "./GoodsClassifyiComp";
import NavViewItem from "./NavViewItem";
import HttpUtils from "../../common/utils/HttpUtils";
import ExConfig from "@module/ExConfig";
import message from "@ui/RJMart/message";
import Uts from "@module/Uts";
export default class NavView extends React.Component {
    constructor(props) {
        super(props);
        this.titles = [
            {
                navId: 1,
                navigationName: "采购首页",
                url: "../purchaser/index.html",
                isOpen: 0,
                isLog: 0
            },
            {
                navId: 2,
                navigationName: "元器件",
                url: "../purchaser/index.html#component",
                isOpen: 0,
                isLog: 0
            },
            {
                navId: 3,
                navigationName: "在线竞价",
                url: "../purchaser/index.html#bidlist",
                isOpen: 0,
                isLog: 0
            },
            {
                navId: 4,
                navigationName: "团购促销",
                url: "../purchaser/index.html#promotionChannel",
                isOpen: 0,
                isLog: 1
            },
            {
                navId: 5,
                navigationName: "帮助中心",
                url: "../purchaser/index.html#help",
                isOpen: 0,
                isLog: 0
            },
            {
                navId: 6,
                navigationName: "视频教程",
                url: "../purchaser/index.html#videoList",
                isOpen: 0,
                isLog: 0
            }
        ];
        this.state = {
            choosed: 0,
            titles: this.titles
        };
    }

    componentDidMount() {
        if (!ExConfig.isLoginAndRegisterPage()) {
            this.getHomeNavigation();
        }
    }

    getHomeNavigation() {
        const isLogin = true;
        HttpUtils.findHomeNavigation()
            .then(res => {
                console.log(res);
                if (res.dtoList) {
                    // res.dtoList[6].url='http://localhost:8032/web/rjdemo/www/v/#/indexPage?navigationBar=1'
                    this.setState({
                        titles: res.dtoList
                    });
                }
            })
            .catch(err => {
                console.log(err);
            });
    }

    render() {
        const { navOpen, hideClassify, isInBid } = this.props;
        const { titles } = this.state;

        if (!titles) {
            return null;
        }
        return (
            <div>
                <div className={"navview-root-wrapper"}>
                    <div style={{ display: "flex", width: 1200 }}>
                        {!hideClassify && (
                            <GoodsClassifyiComp navOpen={navOpen} />
                        )}

                        {titles.map((item, index) => {
                            if (item.navigationName == "视频教程") {
                                localStorage.setItem("vedioUrl", item.url);
                                return (
                                    <NavViewItem
                                        key={index}
                                        index={index}
                                        item={item}
                                    />
                                );
                            } else if (item.navigationName == "帮助中心") {
                                return (
                                    <a
                                        target={"_blank"}
                                        key={item}
                                        className={"nav-view-item-2"}
                                        onClick={() => {
                                            let isSuppLogin = Uts.getCookie(
                                                "id1"
                                            );
                                            if (isSuppLogin) {
                                                window.open(
                                                    "../purchaser/index.html#supphelp"
                                                );
                                            } else {
                                                window.open("./#/HelpCenter");
                                            }
                                        }}
                                    >
                                        <p className={"nav-view-item-p"}>
                                            帮助中心
                                        </p>
                                    </a>
                                );
                            } else {
                                return (
                                    <NavViewItem
                                        key={index}
                                        index={index}
                                        item={item}
                                        isActive={
                                            isInBid &&
                                            item.navigationName == "在线竞价"
                                        }
                                    />
                                );
                            }
                        })}
                    </div>
                </div>
                <div className={"nav-view-bottom-line"} />
            </div>
        );
    }
}
